package com.gitee.vincentzyu.qwq_forge189.client.gui;

import com.gitee.vincentzyu.qwq_forge189.QwqForge189;
import com.gitee.vincentzyu.qwq_forge189.inventory.ContainerDemo;
import com.gitee.vincentzyu.qwq_forge189.item.ItemLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Achievement;
import net.minecraft.stats.AchievementList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.swing.text.html.parser.Entity;

@SideOnly(Side.CLIENT)
public class GuiContainerDemo extends GuiContainer {
    private static final String TEXTURE_PATH = QwqForge189.MODID + ":" + "textures/gui/container/gui_demo.png";
    private static final ResourceLocation TEXTURE = new ResourceLocation(TEXTURE_PATH);

    private static final int BUTTON_UP = 0;
    private static final int BUTTON_DOWN = 1;

    public GuiContainerDemo(ContainerDemo inventorySlotIn){
        super(inventorySlotIn);
        this.xSize = 176;
        this.ySize = 133;
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY){
        GlStateManager.color(1.0F, 1.0F, 1.0F);

        this.mc.getTextureManager().bindTexture(TEXTURE);
        int offsetX = (this.width - this.xSize) / 2, offsetY = (this.height - this.ySize) / 2;

        this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize);
    }

    @Override
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
        this.drawVerticalLine(30, 19, 36, 0xFF000000);
        this.drawHorizontalLine(8, 167, 43, 0xFF000000);

        String title = I18n.format("container.qwq_forge189.demo");
        this.fontRendererObj.drawString(
            title,
            (this.xSize - this.fontRendererObj.getStringWidth(title)) / 2, 6, 0x404040
        );

        ItemStack item = new ItemStack(ItemLoader.qwqItem);
        this.itemRender.renderItemAndEffectIntoGUI(item, 2, 6);
    }

    @Override
    public void initGui(){
        super.initGui();
        int offsetX = (this.width - this.xSize) / 2, offsetY = (this.height - this.ySize) / 2;
        this.buttonList.add(new GuiButton(BUTTON_UP, offsetX+153, offsetY+17, 15,10,""){
            @Override
            public void drawButton(Minecraft mc, int mouseX, int mouseY){
                if ( this.visible ){
                    GlStateManager.color(1.0F, 1.0F, 1.0F);

                    mc.getTextureManager().bindTexture(TEXTURE);
                    int x = mouseX - this.xPosition, y = mouseY - this.yPosition;

                    if ( x>=0 && y>=0 && x<this.width && y<this.height){
                        this.drawTexturedModalRect(this.xPosition, this.yPosition, 1, 146,this.width, this.height);
                    } else {
                        this.drawTexturedModalRect(this.xPosition, this.yPosition, 1, 134,this.width, this.height);
                    }
                }
            }
        });

        this.buttonList.add(new GuiButton(BUTTON_DOWN, offsetX + 153, offsetY + 29, 15, 10, "")
        {
            @Override
            public void drawButton(Minecraft mc, int mouseX, int mouseY)
            {
                if (this.visible)
                {
                    GlStateManager.color(1.0F, 1.0F, 1.0F);

                    mc.getTextureManager().bindTexture(TEXTURE);
                    int x = mouseX - this.xPosition, y = mouseY - this.yPosition;

                    if (x >= 0 && y >= 0 && x < this.width && y < this.height)
                    {
                        this.drawTexturedModalRect(this.xPosition, this.yPosition, 20, 146, this.width, this.height);
                    }
                    else
                    {
                        this.drawTexturedModalRect(this.xPosition, this.yPosition, 20, 134, this.width, this.height);
                    }
                }
            }
        });
    }
}
